package ca.uvic.cs.cogz.stats;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import org.jfree.data.DefaultKeyedValues;
import org.jfree.data.general.DatasetChangeListener;
import org.jfree.data.general.DatasetGroup;
import org.jfree.data.general.PieDataset;

import edu.stanford.smi.protege.model.Cls;

public class NodeStats implements PieDataset {
	/** key constants for the statistics used by the PiePlot */
	private static final String NODES_WITH_MAPPINGS = "Mapped";
	private static final String NODES_WITHOUT_CANDIDATES = "w/o Candidates";
	private static final String NODES_WITH_CANDIDATES = "w/ Candidates";

	private DefaultKeyedValues data;
	
	/** the total number of candidates for this node and all subclass nodes */
	private int totalCount;
	
	/** the number of candidates for this single node */
	private int localCount;
	
	/** the total number of subclasses under this node */
	private int numOfSubclasses;
	
	/** a list of candidate node mappings */
	private LinkedList<Cls> candidates;
	
	public NodeStats() {
		data = new DefaultKeyedValues();
		setTotalCount(0);
		setLocalCount(0);
		setNumOfNodesWithMappings(0);
		setNumOfNodesWithOutCandidates(0);
		setNumOfNodesWithCandidates(0);
		candidates = new LinkedList<Cls>();
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getTotalCount() {
		return totalCount;
	}
	
	public void setNumOfNodesWithOutCandidates(int numOfNodesWithOutCandidates) {
		this.data.addValue(NODES_WITHOUT_CANDIDATES, Math.max(numOfNodesWithOutCandidates, 0));
	}

	public int getNumOfNodesWithOutCandidates() {
		return this.data.getValue(NODES_WITHOUT_CANDIDATES).intValue();
	}

	public void setNumOfNodesWithCandidates(int numOfNodesWithCandidates) {
		this.data.addValue(NODES_WITH_CANDIDATES, numOfNodesWithCandidates);
	}

	public int getNumOfNodesWithCandidates() {
		return this.data.getValue(NODES_WITH_CANDIDATES).intValue();
	}
	
	public void setNumOfNodesWithMappings(int numOfNodesWithMappings) {
		this.data.addValue(NODES_WITH_MAPPINGS, numOfNodesWithMappings);
	}

	public int getNumOfNodesWithMappings() {
		return this.data.getValue(NODES_WITH_MAPPINGS).intValue();
	}
	
	public void setLocalCount(int localCount) {
		this.localCount = localCount;
	}

	public int getLocalCount() {
		return localCount;
	}
	
	public void setNumOfSubclasses(int numOfSubclasses) {
		this.numOfSubclasses = numOfSubclasses;
	}

	public int getNumOfSubclasses() {
		return numOfSubclasses;
	}
	
	public void addCandidate(Cls candidate) {
		candidates.add(candidate);
	}
	
	public LinkedList<Cls> getCandidates() {
		return candidates;
	}

	@SuppressWarnings("unchecked")
	public int getIndex(Comparable arg0) {
		return this.data.getIndex(arg0);
	}

	@SuppressWarnings("unchecked")
	public Comparable getKey(int arg0) {
		return this.data.getKey(arg0);
	}

	@SuppressWarnings("unchecked")
	public List getKeys() {
		return Collections.unmodifiableList(this.data.getKeys());
	}

	@SuppressWarnings("unchecked")
	public Number getValue(Comparable arg0) {
		if (arg0 == null) {
            throw new IllegalArgumentException("Null 'key' argument.");
        }
        return this.data.getValue(arg0);
	}

	public int getItemCount() {
		return this.data.getItemCount();
	}

	public Number getValue(int arg0) {
		Number result = null;
        if (getItemCount() > arg0) {
            result = this.data.getValue(arg0);
        }
        return result;
	}

	public void addChangeListener(DatasetChangeListener arg0) {
		//  Auto-generated method stub
		
	}

	public DatasetGroup getGroup() {
		//  Auto-generated method stub
		return null;
	}

	public void removeChangeListener(DatasetChangeListener arg0) {
		//  Auto-generated method stub
		
	}

	public void setGroup(DatasetGroup arg0) {
		//  Auto-generated method stub
	}
}

